package ManagingSounds
{
	import com.cheezeworld.screens.AScreen;
	import com.cheezeworld.screens.IScreenItem;
	import com.cheezeworld.utils.Input;
	import com.cheezeworld.utils.KeyCode;
	import com.cheezeworld.utils.SoundManager;
	import com.cheezeworld.utils.Utils;
	
	import flash.text.TextField;

	public class MainScreen extends AScreen
	{
		[Embed(source="../assets/gunshot.mp3")]
		private var GunshotSound:Class;
		[Embed(source="../assets/murloc.mp3")]
		private var MurlocSound:Class;
		[Embed(source="../assets/diemaggot.mp3")]
		private var DieMaggotSound:Class;
		[Embed(source="../assets/mario.mp3")]
		private var MarioSound:Class;
		
		public function MainScreen(a_parentScreen:IScreenItem=null)
		{
			super(a_parentScreen);
			
			SoundManager.instance.registerSound( new GunshotSound(), "sound0" );
			SoundManager.instance.registerSound( new MurlocSound(), "sound1" );
			SoundManager.instance.registerSound( new DieMaggotSound(), "sound2" );
			SoundManager.instance.registerSound( new MarioSound(), "music" );
			
			var tf:TextField = Utils.createTextField( this );
			tf.htmlText = Utils.createHtmlText( "Click the mouse to play 1 of 3 random sounds. \n Press 'spacebar' to play music. \n Press 'up' or 'down' to control sound volume.", "#FFFFFF", 16 );
			tf.x = 550/2 - tf.width/2;
			tf.y = 400/2 - tf.height/2;
			
		}
		
		public override function update(a_timePassed:int):void
		{
			if( Input.instance.isMousePressed )
			{
				var rand:int = Math.random() * 4 - 1;
				SoundManager.instance.playSound( "sound" + rand );
			}
			if( Input.instance.isKeyPressed( KeyCode.SPACEBAR ) )
			{
				SoundManager.instance.playMusic( "music" );
			}
			if( Input.instance.isKeyPressed( KeyCode.DOWN ) )
			{
				SoundManager.instance.soundVolume -= .1;
			}
			if( Input.instance.isKeyPressed( KeyCode.UP ) )
			{
				SoundManager.instance.soundVolume += .1;
			}
		}
	}
}